package com.example.himalayaproject.find.recommend.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.himalayaproject.R;
import com.example.himalayaproject.find.recommend.bean.ListDiscoveryColumns;
import com.squareup.picasso.Picasso;

import java.util.Collection;
import java.util.List;

/**
 * Created by Administrator on 2016/12/11.
 */

public class DiscoveryAdapter extends RecyclerView.Adapter<DiscoveryAdapter.ViewHolder> {
    private List<ListDiscoveryColumns> list;
    private Context context;

    public DiscoveryAdapter(List<ListDiscoveryColumns> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(context).inflate(R.layout.recommend_item02_item, parent, false);

        return new ViewHolder(rootView);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if (list.get(position).getTitle() != null) {
            holder.text.setText(list.get(position).getTitle());
        }

        if (list.get(position).getCoverPath() != null) {
            Picasso.with(context).load(list.get(position).getCoverPath()).into(holder.img);
        }
    }

    public void addAllDiscovery(Collection<? extends ListDiscoveryColumns> collection) {
        //int size = collection.size();
        list.addAll(collection);
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView img;
        private TextView text;

        public ViewHolder(View itemView) {
            super(itemView);
            img = ((ImageView) itemView.findViewById(R.id.item02_img));
            text = ((TextView) itemView.findViewById(R.id.item02_text));
        }
    }

}
